package com.baizhi.cmfzdemo.service.impl;

import com.baizhi.cmfzdemo.dao.CmfzUserDao;
import com.baizhi.cmfzdemo.entity.CmfzUser;
import com.baizhi.cmfzdemo.service.CmfzUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 用户业务层实现类
 * Created by 54433 on 2019/4/3.
 */
@Service
public class CmfzUserServiceImpl implements CmfzUserService {
    //封装dao
    @Autowired
    private CmfzUserDao userDao;

    @Override
    public Map queryAllUser(int page, int rows) {
        int page2 = (page-1)*rows;
        Map map = new HashMap();
        try{
            int count  = userDao.getCount();
            List<CmfzUser> users = userDao.queryAllUser(page2,rows);
            map.put("total",count);
            map.put("rows",users);
        }catch (Exception e){
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public List<Map> queryBySex() {
        return userDao.queryBySex();
    }

    @Override
    public List<Map> queryByProvince() {
        return userDao.queryByProvince();
    }

    @Override
    public Map selectByDayCount() {
        Map map = new HashMap();
        map.put("one",userDao.selectByDayCount(7,1));
        map.put("two",userDao.selectByDayCount(14,7));
        map.put("three",userDao.selectByDayCount(21,14));
        return map;
    }
}
